package com.ztgf.shopping.service.shop;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import javax.annotation.Resource;
import com.ztgf.shopping.common.config.YmlConfig;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ztgf.shopping.mapper.shop.ShopPayRefundLogMapper;
import com.ztgf.shopping.models.service.shop.IShopPayRefundLogService;
import com.ztgf.shopping.models.bo.shop.ShopPayRefundLogSaveBO;
import com.ztgf.shopping.models.dto.shop.ShopPayRefundLogDTO;

import java.math.BigDecimal;

/**
 * 店铺退款日志控制器
 *
 * @author zhanghualang
 * @Date 2020-08-25 14:28:42
 */
@DubboService
public class ShopPayRefundLogServiceImpl extends ServiceImpl<ShopPayRefundLogMapper, ShopPayRefundLogDTO> implements IShopPayRefundLogService{

    @Resource
    private YmlConfig ymlConfig;

    @Override
    public boolean add(ShopPayRefundLogSaveBO saveBO) {
        ShopPayRefundLogDTO dto = new ShopPayRefundLogDTO();
        BeanUtils.copyProperties(saveBO,dto);
        Long id = ymlConfig.getPkId();
        dto.setId(id);
        return this.insert(dto);
    }

    @Override
    public Result updateRefund(String paySerial, String payId, Integer status) {
        Wrapper<ShopPayRefundLogDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("pay_serial", paySerial).eq("pay_id", payId);
        ShopPayRefundLogDTO dto = this.selectOne(wrapper);
        if (dto == null){
            return new Result<>(CodeEnum.FAIL_200027);
        }

        ShopPayRefundLogDTO newDto = new ShopPayRefundLogDTO();
        newDto.setId(dto.getId());
        newDto.setStatus(status);
        this.updateById(newDto);
        return new Result<>();
    }
}
